package com.looeyWei;

public class ChiHuo extends Thread{
    private BaoZi bz;

    public ChiHuo(BaoZi bz){
        this.bz = bz;
    }

    @Override
    public void run() {
        while (true){
            synchronized (bz){
                // 没有包子,只能等待
                if(bz.flag == false){
                    try {
                        bz.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                // 吃货被唤醒
                System.out.println("吃货正在吃: " + bz.pi + bz.xian + "的包子");
                bz.flag = false;
                // 唤醒生产者继续生产
                bz.notify();
                System.out.println("吃货吃完了！");
                System.out.println("=========================================");
            }
        }
    }
}
